//
//  OneKeyRepairMainTableCell.m
//  customer
//
//  Created by Holothurian on 2018/10/30.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "OneKeyRepairMainTableCell.h"

/**
 选择地址
 */
@implementation OneKeyRepairMainTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        AutoWeakSelf
        _addImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"addAddressImg"]];
        _addImgView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_addImgView];
        [_addImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView).offset(15);
            make.centerY.equalTo(weakSelf.contentView);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        _rightImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"rightshap"]];
        _rightImgView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_rightImgView];
        [_rightImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.contentView).offset(-15);
            make.centerY.equalTo(weakSelf.contentView);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        
        _selectAddressLabel = [[UILabel alloc]init];
        _selectAddressLabel.font = Font28;
        _selectAddressLabel.text = @"选择地址";
        _selectAddressLabel.textColor = [HSPublic colorWithHexString:@"#000000"];
        [self.contentView addSubview:_selectAddressLabel];
        [_selectAddressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(weakSelf.contentView);
            make.left.equalTo(weakSelf.addImgView.mas_right).offset(10);
            make.right.equalTo(weakSelf.rightImgView.mas_left).offset(-10);
            
        }];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end


/**
 选择维修区域
 */
@implementation OneKeyRepairEmptyRegionTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        AutoWeakSelf
        self.backgroundColor = [HSPublic colorWithHexString:@"#1F89FF"];
        _regionLabel = [[UILabel alloc]init];
        _regionLabel.font = Font(20);
        _regionLabel.text = @"选择维修区域";
        _regionLabel.textAlignment = NSTextAlignmentLeft;
        _regionLabel.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_regionLabel];
        [_regionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView).offset(10);
            make.centerX.equalTo(weakSelf.contentView);
            make.width.mas_equalTo(140);
            make.height.mas_equalTo(50);
        }];
        
        _repairImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"oneRepairWhite"]];
        _repairImgView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_repairImgView];
        [_repairImgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(weakSelf.regionLabel.mas_left).offset(-10);
            make.centerY.equalTo(weakSelf.contentView);
            make.size.mas_equalTo(CGSizeMake(25, 25));
        }];
        self.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    return self;
}

@end

/**
 选择区域后、分割式cell
 */
@implementation  OneKeyRepairRegionTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        AutoWeakSelf
        self.backgroundColor = [HSPublic colorWithHexString:@"#1F89FF"];
        _repairImgViewLeft = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"oneRepairWhite"]];
        _repairImgViewLeft.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_repairImgViewLeft];
        [_repairImgViewLeft mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView).offset(20);
            make.centerY.equalTo(weakSelf.contentView);
            make.size.mas_equalTo(CGSizeMake(25, 25));
        }];
        
        _regionLabelLeft = [[UILabel alloc]init];
        _regionLabelLeft.font = Font(20);
        _regionLabelLeft.numberOfLines = 0;
        _regionLabelLeft.textAlignment = NSTextAlignmentLeft;
        _regionLabelLeft.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_regionLabelLeft];
        [_regionLabelLeft mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView).offset(10);
            make.left.equalTo(weakSelf.repairImgViewLeft.mas_right).offset(10);
            make.width.mas_equalTo(F_DEVICE_W/2.0-60);
            make.height.mas_equalTo(50);
        }];
        
        UIView *verticalView = [[UIView alloc]init];
        verticalView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:verticalView];
        [verticalView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView);
            make.centerX.equalTo(weakSelf.contentView);
            make.size.mas_equalTo(CGSizeMake(2, 70));
        }];
        
        _repairImgViewRight = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"oneRepairWhite"]];
        _repairImgViewRight.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_repairImgViewRight];
        [_repairImgViewRight mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(verticalView.mas_right).offset(20);
            make.centerY.equalTo(weakSelf.contentView);
            make.size.mas_equalTo(CGSizeMake(25, 25));
        }];
        
        _regionLabelRight = [[UILabel alloc]init];
        _regionLabelRight.font = Font(20);
        _regionLabelRight.numberOfLines = 0;
        _regionLabelRight.textAlignment = NSTextAlignmentLeft;
        _regionLabelRight.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_regionLabelRight];
        [_regionLabelRight mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView).offset(10);
            make.left.equalTo(weakSelf.repairImgViewRight.mas_right).offset(10);
            make.width.mas_equalTo(F_DEVICE_W/2.0-60);
            make.height.mas_equalTo(50);
        }];
        self.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    return self;
}

- (void)cellForLayout:(NSArray *)dataArray{
    if ([dataArray count]==2) {
        SelectRepairModel *leftModel = dataArray[0];
        SelectRepairModel *rightModel = dataArray[1];
        self.regionLabelLeft.text = leftModel.parts_name;
        self.regionLabelRight.text = rightModel.parts_name;
    }else if ([dataArray count]==3){
        SelectRepairModel *leftModel = dataArray[0];
        SelectRepairModel *rightModel = dataArray[1];
        SelectRepairModel *bottomModel = dataArray[2];
        self.regionLabelLeft.text = leftModel.parts_name;
        CGFloat width = [HSPublic hsBoundingRectWithWidthString:bottomModel.parts_name SizeHeight:50 Font:[UIFont systemFontOfSize:20]];
        if (width > F_DEVICE_W/2.0-60) {
            self.regionLabelRight.text = rightModel.parts_name;
        }else{
            self.regionLabelRight.text = [NSString stringWithFormat:@"%@\n%@",rightModel.parts_name,bottomModel.parts_name];
        }
        
        
    }
}


- (void)cellForOrderDetailLayout:(NSArray *)dataArray{
    if ([dataArray count]==2) {
        NSString  *leftItemName = dataArray[0];
        NSString *rightItemName = dataArray[1];
        self.regionLabelLeft.text = leftItemName;
        self.regionLabelRight.text = rightItemName;
    }else if ([dataArray count]==3){
        NSString *leftItemName = dataArray[0];
        NSString *rightItemName = dataArray[1];
        NSString *bottomItemName = dataArray[2];
        self.regionLabelLeft.text = leftItemName;
        CGFloat width = [HSPublic hsBoundingRectWithWidthString:bottomItemName SizeHeight:50 Font:[UIFont systemFontOfSize:20]];
        if (width > F_DEVICE_W/2.0-60) {
            self.regionLabelRight.text = rightItemName;
        }else{
            self.regionLabelRight.text = [NSString stringWithFormat:@"%@\n%@",rightItemName,bottomItemName];
        }
        
        
    }
}

@end

/**
 上传图片TableCell
 */
@implementation OneKeyRepairUploadImageTableCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout  alloc]init];
        layout.itemSize = CGSizeMake(80, 80);
        layout.minimumInteritemSpacing =  10;
        layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
        
        _collectionView = [[UICollectionView  alloc]initWithFrame:CGRectMake(0, 0, F_DEVICE_W, 100) collectionViewLayout:layout];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor  whiteColor];
        _collectionView.bounces = NO;
        _collectionView.showsVerticalScrollIndicator = NO;
        _collectionView.showsHorizontalScrollIndicator = NO;
        [self.contentView addSubview:_collectionView];
        [_collectionView registerClass:[OneKeyRepairUploadImageCollectionCell class] forCellWithReuseIdentifier:@"UploadImageCellID"];
        
    }
    return self;
}

- (void)setDataSource:(NSMutableArray *)dataSource{
    _dataSource = dataSource;
    if (self.orderDetailFlag) {
        self.collectionView.contentSize = CGSizeMake(dataSource.count * 100, 100);
    }else{
       self.collectionView.contentSize = CGSizeMake((dataSource.count + 1)*100, 100);
    }
    
    [self.collectionView reloadData];
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    if(self.orderDetailFlag){
        return [self.dataSource count];
    }
    return [self.dataSource count]+1;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    OneKeyRepairUploadImageCollectionCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:@"UploadImageCellID" forIndexPath:indexPath];
    if (indexPath.row == [self.dataSource count]) {
        cell.placeholderView.hidden = NO;
        cell.imgView.hidden = YES;
    }else{
        cell.placeholderView.hidden = YES;
        cell.imgView.hidden = NO;
        NSString *imgStr = self.dataSource[indexPath.row]?:@"";
        [cell.imgView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kCustomerImageIP,imgStr]] placeholderImage:[UIImage imageNamed:@"globalPlaceholder"]];
        if (self.orderDetailFlag) {
            cell.deleteBtn.hidden = YES;
        }else{
            cell.deleteBtn.hidden = NO;
        }
    }
    cell.indexPath = indexPath;
    cell.delegate = self;
    return cell;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
    return UIEdgeInsetsMake(10, 10, 10, 10);
}

- (void)uploadRepairImageCollectionCellAddImage:(NSIndexPath *)indexPath{
    if ([self.delegate respondsToSelector:@selector(uploadImageTableCellAddImage:)]) {
        [self.delegate uploadImageTableCellAddImage:indexPath];
    }
}

- (void)uploadRepairImageCollectionCellTapHaveALook:(NSIndexPath *)indexPath{
    if ([self.delegate respondsToSelector:@selector(uploadImageTableCellTapHaveALook:)]) {
        [self.delegate uploadImageTableCellTapHaveALook:indexPath];
    }
}

- (void)uploadRepairImageCollectionCellDeleteImage:(NSIndexPath *)indexPath{
    if ([self.delegate respondsToSelector:@selector(uploadImageTableCellDeleteImage:)]) {
        [self.delegate uploadImageTableCellDeleteImage:indexPath];
    }
}

@end


/**
 问题描述
 */
@implementation OneKeyRepairQuestionDescriptionTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        AutoWeakSelf
        _questionLabel = [[UILabel alloc]init];
        _questionLabel.font = Font30;
        _questionLabel.text = @"问题描述:";
        _questionLabel.textColor = [HSPublic colorWithHexString:@"#555555"];
        [self.contentView addSubview:_questionLabel];
        [_questionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.contentView).offset(0);
            make.left.equalTo(weakSelf.contentView).offset(15);
            make.size.mas_equalTo(CGSizeMake(F_DEVICE_W - 30, 40));
        }];
        
        _textView = [[UITextView alloc]init];
        _textView.font = Font30;
        _textView.text = @"请描述报修问题详情";
        _textView.textColor = [HSPublic colorWithHexString:@"#808080"];
        [self.contentView addSubview:_textView];
        [_textView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.questionLabel.mas_bottom).offset(0);
            make.left.equalTo(weakSelf.contentView).offset(15);
            make.size.mas_equalTo(CGSizeMake(F_DEVICE_W-30, 110));
        }];
        self.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    return self;
}



@end


/**
 选择服务时间
 */
@implementation OneKeyRepairSelectServiceTimeTableCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        AutoWeakSelf
        _selectServiceLabel = [[UILabel alloc]init];
        _selectServiceLabel.font = Font(17);
        _selectServiceLabel.text = @"选择服务时间";
        _selectServiceLabel.textColor = [HSPublic colorWithHexString:@"808080"];
        [self.contentView addSubview:_selectServiceLabel];
        [_selectServiceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(weakSelf.contentView);
            make.left.equalTo(weakSelf.contentView).offset(15);
            make.width.mas_equalTo(105);
        }];
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.text = @"未选择";
        _timeLabel.font = Font(17);
        _timeLabel.numberOfLines = 0;
        _timeLabel.textAlignment = NSTextAlignmentRight;
        _timeLabel.textColor = [HSPublic colorWithHexString:@"#808080"];
        _timeLabel.userInteractionEnabled = YES;
        [self.contentView addSubview:_timeLabel];
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(weakSelf.contentView);
            make.left.equalTo(weakSelf.selectServiceLabel.mas_right).offset(10);
            make.right.equalTo(weakSelf.contentView).offset(-40);
        }];
        
        _imgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"rightshap"]];
        _imgView.contentMode = UIViewContentModeScaleAspectFit;
        [self.contentView addSubview:_imgView];
        [_imgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(weakSelf.contentView);
            make.right.equalTo(weakSelf.contentView).offset(-15);
            make.size.mas_equalTo(CGSizeMake(15, 15));
        }];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(serviceTimeTapAction)];
        [_timeLabel addGestureRecognizer:tap];
        self.selectionStyle = UITableViewCellSelectionStyleNone;

    }
    return self;
}

- (void)cellForServiceTimeLayout:(NSString *)time{
    if ([time isEqualToString:@"未选择"]||k_Is_Empty(time)) {
        _timeLabel.textColor = [HSPublic colorWithHexString:@"808080"];
        _timeLabel.text = @"未选择";
    }else{
        _timeLabel.text = time;
        _timeLabel.textColor = [HSPublic colorWithHexString:@"333333"];
    }
}

- (void)serviceTimeTapAction{
    if ([self.delegate respondsToSelector:@selector(serviceTimeTapEvent)]) {
        [self.delegate serviceTimeTapEvent];
    }
}

@end
